<template>
    <z-action id="J_contract" type="text" label="插入合同元素" :fields="fields" :beforeSubmit="submit" ref="action">
    </z-action>
</template>

<script>
import elements from './elements';
export default {
    props: {
        editor: {
            type: Object,
            required: true,
        },
    },
    data() {
        return {
            fields: [
                { name: 'label', label: '元素标题' },
                { name: 'type', label: '元素类型', type: 'select', options: elements },
                { name: 'unit', label: '计量单位', visible: (formData) => formData.type === 'number', default: "" },
                { name: 'desc', label: '说明信息', default: "" },
                { name: 'demo', label: '示例数据', default: "" },
                { name: 'def', label: '默认数据', default: "" },
            ],
        };
    },
    methods: {
        submit(formData) {
            // 编辑状态
            if (formData.id) {
                return
            }
            this.editor.commands.insertContent({
                type: "Contract",
                attrs: { ...formData, id: $.uid() }
            });
        },
    },
};
</script>
